#include "player.h"

char *get_player(PLAYER player)
{
    char s[] = " 号玩家 ";
    char id[8];
    char *str;
    int len;

    itoa(player.id, id, 8);
    len = strlen(id) + strlen(s) + strlen(player.name) + 1;
    str = (char *)malloc(len * sizeof(char));
    strcpy(str, id);
    strcat(str, s);
    strcat(str, player.name);
    return str;
}

char *get_deck_of_cards(PLAYER player)
{
    char str[500];
    char spliter[] = " ";
    for (size_t i = 0; i < player.card_count; i++)
    {
        strcat(str, get_poker(player.poker_cards[i]));
        if (i != player.card_count - 1)
            strcat(str, spliter);
    }

    return copyto(str);
}

char *get_player_and_cards(PLAYER player)
{
    char spliter[] = " -> ";
    char *p = get_player(player);
    char *deck = get_deck_of_cards(player);
    KIND_OF_CARDS kind = get_kind_of_cards(player.poker_cards, player.card_count);
    char *kind_str = get_kind_str(kind);

    int len = strlen(spliter) + strlen(p) + strlen(deck) + strlen(kind_str) + 1;
    char *result = (char *)malloc(len * sizeof(char));
    strcpy(result, p);
    strcat(result, spliter);
    strcat(result, deck);
    strcat(result, spliter);
    strcat(result, kind_str);
    return result;
}
